package com.whl.sm.service.impl.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whl.sm.mapper.system.UserCpComMapper;
import com.whl.sm.model.system.UserCpCom;
import com.whl.sm.service.system.UserCpComService;
import org.apache.catalina.User;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuhaolun
 * @since 2021-10-10
 */
@Service
public class UserCpComServiceImpl extends ServiceImpl<UserCpComMapper, UserCpCom> implements UserCpComService {

    @Override
    public List<String> userIdList(String comId) {
        List<UserCpCom> userCpComList = getBaseMapper().selectList(new QueryWrapper<UserCpCom>()
                .eq("com_id",comId));
        List<String> usersId = userCpComList.stream().map(UserCpCom::getUserId).collect(Collectors.toList());
        return usersId;
    }

    @Override
    public String bindMagUser(String comId, List<String> idList) {
        getBaseMapper().delete(new QueryWrapper<UserCpCom>().eq("com_id",comId));
        UserCpCom ucc;
        for (int i = 0; i < idList.size(); i++) {
            ucc = new UserCpCom();
            ucc.setComId(comId);
            ucc.setUserId(idList.get(i));
            ucc.setOperator("5c611a3d87c8dae003ca036484d0ad65");
            getBaseMapper().insert(ucc);
        }
        return "success";

    }
}
